#-------------------------------------------------------------------------------
# Name:        Loading Screen
# Purpose:
#
# Author:      Pablo
#
# Created:     03/08/2012
# Copyright:   (c) Monxcleyr Productions 2012
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame

class Screen():

  """Loading screen class"""

  def __init__(self, screen, common, bgimage, barbox, barfill, barpos, label):
    self.screen = screen
    self.common = common
    self.bg = pygame.image.load('resources/graphics/loading/' + bgimage)
    self.barbox = pygame.image.load('resources/graphics/loading/' + barbox)
    self.barfill = pygame.image.load('resources/graphics/loading/' + barfill)
    self.surface = pygame.Surface(self.common.initsize)
    self.bg.set_colorkey((255,0,255))
    self.barfill.set_colorkey((255,0,255))
    self.barbox.set_colorkey((255,0,255))
    self.pos = barpos
    self.label = label
    self.count = 0

  def reset(self):
    self.count = 0

  def setSteps(self, steps):

    width = self.barfill.get_width()
    self.stepsize = width / steps

  def setText(self, text):
    self.label.setText(text)
    self.label.draw()

  def moveBar(self):

    self.surface.blit(self.bg, (0,0))
    self.surface.blit(self.barbox, self.pos)
    self.surface.blit(self.barfill, self.pos, (0, 0, self.stepsize * self.count, self.barfill.get_height()))
    self.count += 1
    tempsurf = pygame.Surface(self.screen.get_size())
    self.label.screen = self.surface
    self.label.draw()
    pygame.transform.smoothscale(self.surface, (self.screen.get_size()), tempsurf)
    self.screen.blit(tempsurf, (0,0))
    pygame.display.flip()

  def forceDraw(self):
    tempsurf = pygame.Surface(self.screen.get_size())
    pygame.transform.smoothscale(self.surface, (self.screen.get_size()), tempsurf)
    self.screen.blit(tempsurf, (0,0))
    pygame.display.flip()
